package cn.ycc1.boot3websocket.controller;

import cn.ycc1.boot3websocket.handler.WebSocket;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ycc
 * @date 2024/5/2
 */
@RestController
@RequiredArgsConstructor
public class TestController {
    private final WebSocket webSocket;

    @GetMapping("/hello")
    public String hello() {
        return "hello, websocket";
    }

    /**
     * 服务端发消息测试
     * @param message
     * @param userId
     * @return
     * http://localhost:8081/api/test?msg=hello&uid=1
     * ws://localhost:8081/api/websocket/1
     */
    @GetMapping("/test")
    public  String test(@RequestParam("msg") Object message, @RequestParam("uid") String userId) {
//        System.out.println(message);
//        System.out.println(userId);
//        webSocket.sendMessage(message, userId);
        return "test, websocket";
    }
}
